home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2008 September
/
PCWorld_2008-09_cd.bin
/
v cisle
/
sadanastroju
/
bookmark_previews-0.6.5-fx.xpi
/
chrome
/
content
/
tooltip.js
< prev
Wrap
Text File
|
2008-05-27
|
6KB
|
176 lines
var BP = {
_titleNode : null,
_previewNode : null,
get titleNode(){
if (!this._titleNode)
this._titleNode = document.getElementById("bptp_title");
return this._titleNode;
},
get previewNode(){
if (!this._previewNode)
this._previewNode = document.getElementById("bptp_image");
return this._previewNode;
},
_prefs : null,
get prefs(){
if (!this._prefs){
this._prefs = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefService);
this._prefs = this._prefs.getBranch("extensions.bookmarkpreviews.");
}
return this._prefs;
},
_isFF3: null,
get isFF3(){
if (this._isFF3 == null){
var appInfo = Components.classes["@mozilla.org/xre/app-info;1"]
.getService(Components.interfaces.nsIXULAppInfo);
var versionChecker = Components.classes["@mozilla.org/xpcom/version-comparator;1"]
.getService(Components.interfaces.nsIVersionComparator);
if(versionChecker.compare(appInfo.version, "3.0a") >= 0) {
this._isFF3 = true;
} else{
this._isFF3 = false;
}
}
return this._isFF3;
},
_tree: null,
get tree(){
if (!this._tree){
this._tree = document.getElementById("bookmarks-view");
}
return this._tree;
},
get children(){
if (this.isFF3){
return document.getElementById("bookmarks-view-children");
} else {
return this.tree.tree.getElementsByTagName("treechildren");
}
},
load: function bp_load(event){
BP.prefs.QueryInterface(Components.interfaces.nsIPrefBranch2).addObserver("",BP,false);
var show = BP.prefs.getBoolPref("sidebarTooltips");
if (!show){
BP.disableTooltip();
} else{
BP.enableTooltip();
}
},
unload: function bp_unload(event){
BP.prefs.removeObserver("",BP,false);
BP.disableTooltip();
},
handleEvent: function bp_handleevent(event){
if (event.type == "mousemove"){
BP.x = event.clientX;
BP.y = event.clientY;
}
},
observe: function bp_observe(subject, topic, data){
if (topic != "nsPref:changed"){
return;
}
if (data == "sidebarTooltips"){
var show = this.prefs.getBoolPref("sidebarTooltips");
if (show){
this.enableTooltip();
} else{
this.disableTooltip();
}
}
},
disableTooltip: function bp_disabletooltip(){
if (this.isFF3)
this.children.removeAttribute("tooltip");
else {
var eles = this.children;
for (var i = 0; i<eles.length;i++){
eles[i].removeAttribute("tooltip");
}
}
try{
this.tree.removeEventListener("mousemove",this,false);
}catch(e){}
},
enableTooltip: function bp_enabletooltip(){
this.tree.addEventListener("mousemove",this.handleEvent,false);
if (this.isFF3)
this.children.setAttribute("tooltip","bookmarkpreviewsTooltip");
else {
var eles = this.children;
for (var i = 0; i<eles.length;i++){
eles[i].setAttribute("tooltip","bookmarkpreviewsTooltip");
}
}
},
tooltipShowing: function bp_tooltipshowing(event){
this.previewNode.src = null;
this.previewNode.removeAttribute("style");
this.previewNode.collapsed = true;
return true;
},
tooltipShown: function bp_tooltipshown(event){
var tooltip = event.target;
var x = BP.x; var y = BP.y;
var row = this.tree.treeBoxObject.getRowAt(x,y);
var title = {}, url = {};
this.getProperties(row,title,url);
this.titleNode.setAttribute("value",title.value);
var src = this.getImage(url.value);
if (src){
var image = new Image();
image.onload = function(event){
var target = BP.previewNode;
var maxwidth = 300;
var width = image.width;
var height = image.height;
if (width>maxwidth){
height = maxwidth / width * height;
target.setAttribute("style","max-width: "+maxwidth+"px; max-height: "+height+"px");
target.src = src;
}
};
image.src = src;
if (image.complete) image.onload();
this.previewNode.collapsed = false;
} else{
this.previewNode.collapsed = true;
}
},
getImage: function bp_getimage(url){
if (url){
var file = PreviewServiceUtils.getPreviewFile(url);
if (file.exists() && file.isFile()){
var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
var uri = ios.newFileURI(file);
if (uri)
return uri.spec;
}
}
return null;
},
getProperties: function bp_getproperties(index, title, url){
if (index > -1){
if (this.isFF3){
var node = this.tree.view.nodeForTreeIndex(index);
title.value = node.title;
url.value = node.uri;
} else {
var node = this.tree.getRowResource(index);
var nameProp = RDF.GetResource("http://home.netscape.com/NC-rdf#Name");
var urlProp = RDF.GetResource("http://home.netscape.com/NC-rdf#URL")
var itemValue = BMDS.GetTarget(node, nameProp, true);
if (itemValue && itemValue instanceof Components.interfaces.nsIRDFLiteral)
title.value = itemValue.Value;
var itemValue = BMDS.GetTarget(node, urlProp, true);
if (itemValue && (itemValue instanceof Components.interfaces.nsIRDFLiteral || itemValue.Value))
url.value = itemValue.Value;
}
}
}
}
addEventListener("load",BP.load,false);
addEventListener("unload",BP.unload,false);